<?php

namespace app\common\model;

use org\util\TreeUtil;

class ShopPromotionGroupbuyModel extends BaseModel
{
    protected $name = 'shop_promotion_groupbuy'; //定义用户表
    //开启自动写入时间戳
    protected $autoWriteTimestamp = false;
    // 定义自动完成的属性
    protected $auto = []; //新增修改
    protected $insert = []; //插入
    protected $update = []; //修改
    protected $type = ['begin_time' => 'timestamp', 'end_time' => 'timestamp'];//类型管理

    /**
     * 读取缩略图
     * @param $value
     * @param $data
     * @return string
     */
    protected function getGoodsThumbAttr($value, $data)
    {
        if (empty($data['album'])) {
            return '';
        } else {
            $album = explode('|', $data['album']);
            return $album[0];
        }
    }

    public function getPromotionStatusTextAttr($value, $data)
    {
        $state = [
            0 => '<span class="label label-warning">未开始</span>',
            1 => '<span class="label label-success">正常</span>',
            -1 => '<span class="label label-danger">已结束</span>',
        ];
        return $state[$data['promotion_status']];
    }


}